(function(b, c) {
    var a = function() {};
    c.extend(true, a, {
        setting: {
            ajax: {
                type: "POST",
                asyn: true,
                contentType: "application/x-www-form-urlencoded",
                data: null,
                url: "",
                dataType: "json",
                success: null,
                error: null,
                showError: true,
                cover: function() {
                    return c("body")
                }
            }
        },
        ajax: function(g) {
            var h = this;
            var i = g.success || c.noop();
            var e = g.error || c.noop();
            var f = g.cover !== false && c.fn.cover !== undefined && (g.cover && g.cover() || this.setting.ajax.cover());
            var d = g.showError !== false;
            if (f) {
                f.cover()
            }
            return this.doAjax(c.extend(true, g, {
                success: function() {
                    if (c.isFunction(i)) {
                        i.apply(null, arguments)
                    }
                    if (f) {
                        f.uncover()
                    }
                },
                error: function() {
                    if (c.isFunction(e)) {
                        e.apply(null, arguments)
                    }
                    if (f) {
                        f.uncover()
                    }
                    if (d) {
                        h.showError(arguments[1], arguments[2])
                    }
                }
            }))
        },
        doAjax: function(d) {
            d = c.extend(true, {},
            a.setting, d);
            return c.ajax(d)
        },
        getFormData: function(d) {
            var e = {};
            if (d && d.length && d.length > 0) {
                d.find("[name]").each(function() {
                    var f = this.tagName.toLowerCase(),
                    g = c(this);
                    if ("|input|select|textarea|".indexOf("|" + f + "|") > -1) {
                        e[this.name] = g.val()
                    } else {
                        e[this.name] = g.text() || g.html()
                    }
                })
            }
            return e
        },
        showError: function(e, d) {
            if (c.gritter) {
                jQuery.gritter.add({
                    title: e || "警告",
                    text: d,
                    class_name: "growl-danger",
                    image: "images/screen.png",
                    sticky: true,
                    time: ""
                })
            } else {
                alert(d)
            }
        }
    });
    c.extend(true, a, {
        CODE: {
            SUCCESS_DATA: 10000,
            SUCCESS_NODATA: 10001,
            PARAM_ERROR: 10002,
            SERVICE_EXCEPTION: 10003
        }
    });
    c.extend(true, c, {
        fn: {
            submitForm: function(d) {
                return c(this).each(function() {
                    var f = c(this),
                    e = a.getFormData(f);
                    d = c.extend(true, {},
                    a.setting.ajax, {
                        data: e,
                        url: f.attr("action") || "",
                        type: f.attr("method") || "POST"
                    },
                    d);
                    a.doAjax(d)
                })
            }
        }
    });
    b.Ajax = a
} (window, jQuery));